#include "textqgsmapcanvasitem.h"
#include <QDebug>
TextQgsMapCanvasItem::TextQgsMapCanvasItem(QgsMapCanvas *canvas)
: QgsMapCanvasItem(canvas)
{

}

void TextQgsMapCanvasItem::setText(const QString &text)
{
    mText = text; // 默认自动调用paint函数
}

void TextQgsMapCanvasItem::setPosition(const QPointF &position)
{
    mPoint = position;
}

void TextQgsMapCanvasItem::paint(QPainter *painter)
{

    if (mText.isEmpty())
        return;
    qDebug() << "222222 :" << mText;
    // // 设置文本的颜色和字体
    painter->setPen(Qt::black);
    painter->setFont(QFont("Arial", 8));
    // 绘制文本
    painter->drawText(mPoint, mText);

}
